package com.atguigu.multiReading;

public class demo13 {
    public static void main(String[] args) {
        String[] words=new String[]{"cat","bt","hat","tree"};
        String chars="atach";
        System.out.println(Solution.countCharacters(words,chars));
    }
}
class Solution {
    public static int countCharacters(String[] words, String chars) {
        int res=0;
        for(int i=0;i<words.length;i++){
            int[] a=new int[128];
            for(int j=0;j<chars.length();j++){
                a[chars.charAt(j)]++;
            }
            for(int j=0;j<words[i].length();j++){
                a[words[i].charAt(j)]--;
            }
            for(int j=0;j<a.length;j++){
                if(a[j]<0){
                    break;
                }else{
                    res+=words[i].length();
                    break;
                }
            }
        }
        return res;
    }
}
